home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kcmenumngr.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  3.4 KB  |  115 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1999 Matthias Ettrich (ettrich@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef KCMENUMNGR_H
  21. #define KCMENUMNGR_H
  22.  
  23.  
  24. class QWidget;
  25. class QPopupMenu;
  26. class KContextMenuManagerPrivate;
  27. #include <qobject.h>
  28. #include <qptrdict.h>
  29. #include <qkeysequence.h>
  30.  
  31. #include <kdelibs_export.h>
  32.  
  33. /**
  34. @short Convenience class to mangage context menus
  35. @author Matthias Ettrich <ettrich@kde.org>
  36.  
  37. KContextMenuManager manages configurable context popup menus.  Instead
  38. of reimplementing QWidget::mousePressEvent() or
  39.  QWidget::mouseReleaseEvent() and/or QWidget::keyPressEvent(), simply
  40. create the popup menu and insert it into the context menu manager with
  41. the static function insert().
  42.  
  43. Example:
  44. \code
  45.    KContextMenuManager::insert( myWidget, myPopupMenu );
  46. \endcode
  47.  
  48.  
  49. Context menus are invoked with either a special shortcut key (usually
  50. the menu key) or the right mouse button.
  51.  
  52. Menus are configurable in the [ContextMenus] group of the application's
  53. configuration file, usually in kdeglobals:
  54. \code
  55.     [ContextMenus]
  56.     ShowOnPress=true|false
  57. \endcode
  58.  
  59. @p ShowOnPress defines whether the menu shall be shown on mouse
  60. press or on mouse release.
  61.  
  62. The shortcut key to invoke the context menu is defined in the standard
  63. [Keys] section of the application configuration:
  64. \code
  65.    [Keys]
  66.    ...
  67.    PopupContextMenu=Menu
  68.    ...
  69. \endcode
  70. The key can be configured with the standard keys module in the KDE control center.
  71.  
  72. If the popup menu is invoked with the keyboard shortcut, it's shown at
  73. the position of the micro focus hint of the widget ( QWidget::microFocusHint() ).
  74. */
  75.  
  76. class KDEUI_EXPORT KContextMenuManager : public QObject
  77. {
  78.     Q_OBJECT
  79. public:
  80.  
  81.     /**
  82.        Makes @p popup a context popup menu for widget @p widget.
  83.  
  84.        Ownership of the popup menu is not transferred to the context
  85.        menu manager.
  86.     */
  87.     static void insert( QWidget* widget, QPopupMenu* popup );
  88.  
  89.     /**
  90.      * Use this method to get information about when a popup menu
  91.      * should be activated. This can be useful if the popup menu is
  92.      * to be activated from a listview.
  93.      *
  94.      * @return true if the menu should be made visible on a button press
  95.      *         or false after a button press-release sequence.
  96.      */
  97.      static bool showOnButtonPress( void );
  98.  
  99. private slots:
  100.     void widgetDestroyed();
  101. private:
  102.     KContextMenuManager( QObject* parent = 0, const char* name  = 0);
  103.     ~KContextMenuManager();
  104.     bool eventFilter( QObject *, QEvent * );
  105.     QPtrDict<QPopupMenu> menus;
  106.     bool showOnPress;
  107.     QKeySequence menuKey;
  108.     static KContextMenuManager* manager;
  109.     friend class I_really_like_this_class; // avoid warning
  110.  
  111.     KContextMenuManagerPrivate *d;
  112. };
  113.  
  114. #endif
  115.